/**
 * 权限相关的数据
 * Created by gcc on 2017/9/29.
 */

import Vue from 'vue'

// 页码相关
let page = {
  total: 1,
  startIndex: 0,
  stepNumber: 40,
  currentPage: 1
};

//页面状态相关
let status = {
  //查看图片
  modalImage: {
    isShow: false,
    url: ''
  },
  //查看图片
  modalSearch: {
    isShow: false,
  },
};

// 和网络交互相关的参数
let params = {
  //搜索条件
  searchParams:{
    startCreatedate:"",
    endCreatedate:"",
    productCode:"",
    categoryCode:"",
    categoryLevel: "",
  },
  startEndDate: [],
};

// 页面的数据源
let data = {
  productOrderList: [],
  //从服务器返回的分类数据
  classificationList:[],
  //转换控件需要的分类数据
  categoryList:[],
  dateRange: {
    disabledDate (date) {
      return date && date.valueOf() > Date.now() - 86400000;
    }
  },
};

let table = function (self) {
  let titles = [

    {
      type: 'index',
      title: '#',
      align: 'center',
      width: 60,
    },
    {
      title: '产品编码',
      key: 'productCode',
      align: 'center',
      width:200,
      render: (h, params) => {
        let productUrl = Vue.prototype.$tiyProductUrl(params.row.productCode);
        return h('div',[h('a',{
          attrs:{href:productUrl,target:'_blank'}
        },params.row.productCode)]);
      }
    },
    {
      title: '产品名称',
      key: 'productName',
      align: 'left',
      minWidth: 200,
    },
    {
      title: '产品图片',
      key: 'colorTryImg',
      width: 150,
      align: 'center',
      render: (h, params) => {
        {
          let imageUrl = params.row.productImg;
          let yunPath = Vue.prototype.$store.getters.imgPrefix;
          if(imageUrl){
            imageUrl = yunPath + imageUrl;
            return h('div', [h('img', {
              attrs: {src: imageUrl, height: 60},
              on: {
                click: () => {
                  status.modalImage.url = imageUrl;
                  status.modalImage.isShow = true;
                }
              }
            }, imageUrl)
            ]);
          } else {
            return h('div',"");
          }
        }
      }
    },
    {
      title: '订单数',
      key: 'total',
      width: 120,
      align: 'center'
    },
    {
      title: '销量',
      key: 'amount',
      width: 120,
      align: 'center'
    },
    {
      title: '销售额',
      key: 'payment',
      width: 120,
      align: 'center'
    }
  ]

  return self.$authTableTitles(titles)
}

export default  {
  tPage: page,
  tParams: params,
  tStatus: status,
  tableTitles: table,
  tData: data
};
